using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using Musicman.Common.Entities;
using Musicman.Business;

namespace MusicmanWeb
{
    public partial class Default : MusicmanPage
    {
        protected override void Page_Load(object sender, EventArgs e)
        {
            ReddirectNonActiveSession();

            if (User.Identity.IsAuthenticated && !IsPostBack)
            {
                Musicman.Common.Entities.User user = UserManager.Instance.GetUser(Int64.Parse(User.Identity.Name));

                statsPnl.Visible = true;

                List<SearchJob> jobs = SearchJobManager.Instance.LoadAllSearchJobs();
                JobsGV.DataSource = jobs;

                List<User> topLoggers = UserManager.Instance.LoadTopWebLoggers(5);
                TopLoggersGV.DataSource = topLoggers;

                List<User> topDownloaders = UserManager.Instance.LoadTopDownloaders(5);
                TopDownloadersGV.DataSource = topDownloaders;

                DataBind();
            }
        }

        protected void TopLoggersGV_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            Musicman.Common.Entities.User user = e.Row.DataItem as Musicman.Common.Entities.User;
            if (user != null)
            {
                e.Row.Cells[0].Text = String.Format("{0} {1}", user.Firstname, user.Lastname);
                e.Row.Cells[1].Text = user.UserStats.TotalLogsWeb.ToString();
            }
        }

        protected void TopDownloadersGV_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            Musicman.Common.Entities.User user = e.Row.DataItem as Musicman.Common.Entities.User;
            if (user != null)
            {
                e.Row.Cells[0].Text = String.Format("{0} {1}", user.Firstname, user.Lastname);
                e.Row.Cells[1].Text = user.UserStats.TotalFilesDownloaded.ToString();
            }
        }
    }
}
